package com.itemp.ms66btreceiver;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.Handler;
import android.util.Log;

import java.io.File;
import java.io.FileInputStream;

public class BootReceiver extends BroadcastReceiver {
    private String TAG = "BootReceiver";
    @Override
    public void onReceive(Context context, Intent intent) {
        Log.d(TAG, intent.getAction());
        if(Intent.ACTION_BOOT_COMPLETED.equals(intent.getAction())){
            new Handler().postDelayed(() -> {
                ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
                NetworkInfo networkInfo = cm.getActiveNetworkInfo();
                if (networkInfo != null
                        && networkInfo.isConnected()
                        && networkInfo.getType() == ConnectivityManager.TYPE_WIFI) {
                    Log.d(TAG,intent.getAction() + "\n" + " WIFI Connected");
                }else{
//                    Intent intent1 = new Intent(context,MainActivity.class);
//                    intent1.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
//                    context.startActivity(intent1);
                }
            }, 5*1000);
        }
    }
}